﻿package idv.cjcat.monica.platformer.player {
	import idv.cjcat.rusher.engine.logger.LogType;
	import idv.cjcat.rusher.engine.ui.KeyManager;
	import idv.cjcat.rusher.geom.Vec2D;
	
	internal class StandingState extends PlayerState {
		
		public function StandingState(controller:PlayerController, direction:Number) {
			super(controller, direction);
			controller.engine.logger.log("Entered state: StandingState", LogType.INFO, controller);
			
			this.controller.jumpCount = 0;
			
			var vel:Vec2D = getVelocity();
			setVelocity(new Vec2D(0, 0));
			
			if (controller.moving) {
				if (controller.dashing) {
					setState(RunningState);
					setPlayerMovieClip(renderTarget.running, true);
				} else {
					setState(WalkingState);
					setPlayerMovieClip(renderTarget.moving, true);
				}
			}
		}
		
		override public function startJump():void {
			if (controller.jumpCount < PlayerController.MAX_JUMPS) {
				setState(JumpingUpState);
				setPlayerMovieClip(renderTarget.jumpingUpVertical, false);
			}
		}
		
		override public function onTick(time:Number):void {
			var vel:Vec2D = getVelocity();
			if (vel.y > 0 && !controller.onFloor) {
				setState(FallingDownState);
				setPlayerMovieClip(renderTarget.fallingDown, false);
			}
			
			if (controller.moving) {
				if (controller.dashing) {
					setState(RunningState);
					setPlayerMovieClip(renderTarget.running, true);
					return;
				}
				else {
					setState(WalkingState);
					setPlayerMovieClip(renderTarget.moving, true);
					return;
				}
			}
		}
	}
}